<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>格式化一个本地时间／日期</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.date-timezone-set.html">date_timezone_set</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.getdate.html">getdate</a></div>
 <div class="up"><a href="ref.datetime.html">Date/Time 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.date" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">date</h1>
  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">date</span> &mdash; <span class="dc-title">格式化一个本地时间／日期</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.date-description">
  <h3 class="title">说明</h3>
   <div class="methodsynopsis dc-description">
    <span class="type">string</span> <span class="methodname"><strong>date</strong></span>
     ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$format</code></span>
    [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$timestamp</code></span>
   ] )</div>

  <p class="para rdfs-comment">
   返回将整数 <em><code class="parameter">timestamp</code></em>
   按照给定的格式字串而产生的字符串。如果没有给出时间戳则使用本地当前时间。换句话说，<em><code class="parameter">timestamp</code></em>
   是可选的，默认值为 <span class="function"><a href="function.time.html" class="function">time()</a></span>。
  </p>
  <div class="tip"><strong class="tip">Tip</strong>
   <p class="para">
    自 PHP 5.1.1 起有几个有用的<a href="datetime.constants.html" class="link">常量</a>可用作标准的日期／时间格式来指定
    <em><code class="parameter">format</code></em> 参数。
   </p>
  </div>
  <div class="tip"><strong class="tip">Tip</strong>
   <p class="para">
    自 PHP 5.1 起在 <var class="varname"><var class="varname"><a href="reserved.variables.server.html" class="classname">$_SERVER['REQUEST_TIME']</a></var></var>
    中保存了发起该请求时刻的时间戳。
   </p>
  </div>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    有效的时间戳典型范围是格林威治时间 1901 年 12 月 13 日 20:45:54
    到 2038 年 1 月 19 日 03:14:07。（此范围符合 32
    位有符号整数的最小值和最大值）。不过在 PHP 5.1 之前此范围在某些系统（如
    Windows）中限制为从 1970 年 1 月 1 日到 2038 年 1 月 19 日。
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    要将字符串表达的时间转换成时间戳，应该使用
    <span class="function"><a href="function.strtotime.html" class="function">strtotime()</a></span>。此外一些数据库有一些函数将其时间格式转换成时间戳（例如
    MySQL 的 <a href="http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html" class="link external">&raquo;&nbsp;UNIX_TIMESTAMP</a> 函数）。
   </p>
  </p></blockquote>
  <p class="para">
   <table class="doctable table">
    <caption><strong>格式字串可以识别以下 <em><code class="parameter">format</code></em> 参数的字符串</strong></caption>
    
     <thead>
      <tr>
       <th><em><code class="parameter">format</code></em> 字符</th>
       <th>说明</th>
       <th>返回值例子</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td style="text-align: center;"><em class="emphasis">日</em></td>
       <td>---</td>
       <td>---</td>
      </tr>

      <tr>
       <td><em>d</em></td>
       <td>月份中的第几天，有前导零的 2 位数字</td>
       <td><em>01</em> 到 <em>31</em></td>
      </tr>

      <tr>
       <td><em>D</em></td>
       <td>星期中的第几天，文本表示，3 个字母</td>
       <td><em>Mon</em> 到 <em>Sun</em></td>
      </tr>

      <tr>
       <td><em>j</em></td>
       <td>月份中的第几天，没有前导零</td>
       <td><em>1</em> 到 <em>31</em></td>
      </tr>

      <tr>
       <td><em>l</em>（“L”的小写字母）</td>
       <td>星期几，完整的文本格式</td>
       <td><em>Sunday</em> 到 <em>Saturday</em></td>
      </tr>

      <tr>
       <td><em>N</em></td>
       <td>ISO-8601 格式数字表示的星期中的第几天（PHP 5.1.0 新加）</td>
       <td><em>1</em>（表示星期一）到 <em>7</em>（表示星期天）</td>
      </tr>

      <tr>
       <td><em>S</em></td>
       <td>每月天数后面的英文后缀，2 个字符</td>
       <td><em>st</em>，<em>nd</em>，<em>rd</em>
        或者 <em>th</em>。可以和 <em>j</em> 一起用</td>
      </tr>

      <tr>
       <td><em>w</em></td>
       <td>星期中的第几天，数字表示</td>
       <td><em>0</em>（表示星期天）到 <em>6</em>（表示星期六）</td>
      </tr>

      <tr>
       <td><em>z</em></td>
       <td>年份中的第几天</td>
       <td><em>0</em> 到 <em>365</em></td>
      </tr>

      <tr>
       <td style="text-align: center;"><em class="emphasis">星期</em></td>
       <td>---</td>
       <td>---</td>
      </tr>

      <tr>
       <td><em>W</em></td>
       <td>ISO-8601 格式年份中的第几周，每周从星期一开始（PHP 4.1.0 新加的）</td>
       <td>例如：<em>42</em>（当年的第 42 周）</td>
      </tr>

      <tr>
       <td style="text-align: center;"><em class="emphasis">月</em></td>
       <td>---</td>
       <td>---</td>
      </tr>

      <tr>
       <td><em>F</em></td>
       <td>月份，完整的文本格式，例如 January 或者 March</td>
       <td><em>January</em> 到 <em>December</em></td>
      </tr>

      <tr>
       <td><em>m</em></td>
       <td>数字表示的月份，有前导零</td>
       <td><em>01</em> 到 <em>12</em></td>
      </tr>

      <tr>
       <td><em>M</em></td>
       <td>三个字母缩写表示的月份</td>
       <td><em>Jan</em> 到 <em>Dec</em></td>
      </tr>

      <tr>
       <td><em>n</em></td>
       <td>数字表示的月份，没有前导零</td>
       <td><em>1</em> 到 <em>12</em></td>
      </tr>

      <tr>
       <td><em>t</em></td>
       <td>给定月份所应有的天数</td>
       <td><em>28</em> 到 <em>31</em></td>
      </tr>

      <tr>
       <td style="text-align: center;"><em class="emphasis">年</em></td>
       <td>---</td>
       <td>---</td>
      </tr>

      <tr>
       <td><em>L</em></td>
       <td>是否为闰年</td>
       <td>如果是闰年为 <em>1</em>，否则为 <em>0</em></td>
      </tr>

      <tr>
       <td><em>o</em></td>
       <td>ISO-8601 格式年份数字。这和
        <em>Y</em> 的值相同，只除了如果 ISO
        的星期数（<em>W</em>）属于前一年或下一年，则用那一年。（PHP 5.1.0 新加）</td>
       <td>Examples: <em>1999</em> or <em>2003</em></td>
      </tr>

      <tr>
       <td><em>Y</em></td>
       <td>4 位数字完整表示的年份</td>
       <td>例如：<em>1999</em> 或 <em>2003</em></td>
      </tr>

      <tr>
       <td><em>y</em></td>
       <td>2 位数字表示的年份</td>
       <td>例如：<em>99</em> 或 <em>03</em></td>
      </tr>

      <tr>
       <td style="text-align: center;"><em class="emphasis">时间</em></td>
       <td>---</td>
       <td>---</td>
      </tr>

      <tr>
       <td><em>a</em></td>
       <td>小写的上午和下午值</td>
       <td><em>am</em> 或 <em>pm</em></td>
      </tr>

      <tr>
       <td><em>A</em></td>
       <td>大写的上午和下午值</td>
       <td><em>AM</em> 或 <em>PM</em></td>
      </tr>

      <tr>
       <td><em>B</em></td>
       <td>Swatch Internet 标准时</td>
       <td><em>000</em> 到 <em>999</em></td>
      </tr>

      <tr>
       <td><em>g</em></td>
       <td>小时，12 小时格式，没有前导零</td>
       <td><em>1</em> 到 <em>12</em></td>
      </tr>

      <tr>
       <td><em>G</em></td>
       <td>小时，24 小时格式，没有前导零</td>
       <td><em>0</em> 到 <em>23</em></td>
      </tr>

      <tr>
       <td><em>h</em></td>
       <td>小时，12 小时格式，有前导零</td>
       <td><em>01</em> 到 <em>12</em></td>
      </tr>

      <tr>
       <td><em>H</em></td>
       <td>小时，24 小时格式，有前导零</td>
       <td><em>00</em> 到 <em>23</em></td>
      </tr>

      <tr>
       <td><em>i</em></td>
       <td>有前导零的分钟数</td>
       <td><em>00</em> 到 <em>59</em>&gt;</td>
      </tr>

      <tr>
       <td><em>s</em></td>
       <td>秒数，有前导零</td>
       <td><em>00</em> 到 <em>59</em>&gt;</td>
      </tr>

      <tr>
       <td style="text-align: center;"><em class="emphasis">时区</em></td>
       <td>---</td>
       <td>---</td>
      </tr>

      <tr>
       <td><em>e</em></td>
       <td>时区标识（PHP 5.1.0 新加）</td>
       <td>例如：<em>UTC</em>，<em>GMT</em>，<em>Atlantic/Azores</em></td>
      </tr>

      <tr>
       <td><em>I</em></td>
       <td>是否为夏令时</td>
       <td>如果是夏令时为 <em>1</em>，否则为 <em>0</em></td>
      </tr>

      <tr>
       <td><em>O</em></td>
       <td>与格林威治时间相差的小时数</td>
       <td>例如：<em>+0200</em></td>
      </tr>

      <tr>
       <td><em>P</em></td>
       <td>与格林威治时间（GMT）的差别，小时和分钟之间有冒号分隔（PHP 5.1.3 新加）</td>
       <td>例如：<em>+02:00</em></td>
      </tr>

      <tr>
       <td><em>T</em></td>
       <td>本机所在的时区</td>
       <td>例如：<em>EST</em>，<em>MDT</em>（【译者注】在 Windows
       下为完整文本格式，例如“Eastern Standard Time”，中文版会显示“中国标准时间”）。</td>
      </tr>

      <tr>
       <td><em>Z</em></td>
       <td>时差偏移量的秒数。UTC 西边的时区偏移量总是负的，UTC 东边的时区偏移量总是正的。</td>
       <td><em>-43200</em> 到 <em>43200</em></td>
      </tr>

      <tr>
       <td style="text-align: center;"><em class="emphasis">完整的日期／时间</em></td>
       <td>---</td>
       <td>---</td>
      </tr>

      <tr>
       <td><em>c</em></td>
       <td>ISO 8601 格式的日期（PHP 5 新加）</td>
       <td>2004-02-12T15:19:21+00:00</td>
      </tr>

      <tr>
       <td><em>r</em></td>
       <td>RFC 822 格式的日期</td>
       <td>例如：<em>Thu, 21 Dec 2000 16:01:07 +0200</em></td>
      </tr>

      <tr>
       <td><em>U</em></td>
       <td>从 Unix 纪元（January 1 1970 00:00:00 GMT）开始至今的秒数</td>
       <td>参见 <span class="function"><a href="function.time.html" class="function">time()</a></span></td>
      </tr>

     </tbody>
    
   </table>

  </p>
  <p class="para">
   格式字串中不能被识别的字符将原样显示。<em>Z</em> 格式在使用
   <span class="function"><a href="function.gmdate.html" class="function">gmdate()</a></span> 时总是返回 <em>0</em>。
  </p>
  <p class="para">
   <div class="example" id="example-2235">
    <p><strong>Example #1 <span class="function"><strong>date()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;设定要用的默认时区。自&nbsp;PHP&nbsp;5.1&nbsp;可用<br /></span><span style="color: #0000BB">date_default_timezone_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'UTC'</span><span style="color: #007700">);<br /><br /><br /></span><span style="color: #FF8000">//&nbsp;输出类似：Monday<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"l"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;输出类似：Monday&nbsp;15th&nbsp;of&nbsp;August&nbsp;2005&nbsp;03:12:46&nbsp;PM<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'l&nbsp;dS&nbsp;\of&nbsp;F&nbsp;Y&nbsp;h:i:s&nbsp;A'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;输出：July&nbsp;1,&nbsp;2000&nbsp;is&nbsp;on&nbsp;a&nbsp;Saturday<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"July&nbsp;1,&nbsp;2000&nbsp;is&nbsp;on&nbsp;a&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"l"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mktime</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">7</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2000</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">/*&nbsp;在格式参数中使用常量&nbsp;*/<br />//&nbsp;输出类似：Mon,&nbsp;15&nbsp;Aug&nbsp;2005&nbsp;15:12:46&nbsp;UTC<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #0000BB">DATE_RFC822</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;输出类似：2000-07-01T00:00:00+00:00<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #0000BB">DATE_ATOM</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mktime</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">7</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2000</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="para">
   在格式字串中的字符前加上反斜线来转义可以避免它被按照上表解释。如果加上反斜线后的字符本身就是一个特殊序列，那还要转义反斜线。
   <div class="example" id="example-2236">
    <p><strong>Example #2 在 <span class="function"><strong>date()</strong></span> 中转义字符</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;prints&nbsp;something&nbsp;like:&nbsp;Wednesday&nbsp;the&nbsp;15th<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"l&nbsp;\\t\h\e&nbsp;jS"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="para">
   可以把 <span class="function"><strong>date()</strong></span> 和
   <span class="function"><a href="function.mktime.html" class="function">mktime()</a></span> 结合使用来得到未来或过去的日期。
   <div class="example" id="example-2237">
    <p><strong>Example #3 <span class="function"><strong>date()</strong></span> 和 <span class="function"><a href="function.mktime.html" class="function">mktime()</a></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$tomorrow&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mktime</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"m"</span><span style="color: #007700">)&nbsp;&nbsp;,&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"d"</span><span style="color: #007700">)+</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"Y"</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$lastmonth&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mktime</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"m"</span><span style="color: #007700">)-</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"d"</span><span style="color: #007700">),&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"Y"</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$nextyear&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mktime</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"m"</span><span style="color: #007700">),&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"d"</span><span style="color: #007700">),&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"Y"</span><span style="color: #007700">)+</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
   <blockquote class="note"><p><strong class="note">Note</strong>: 
    <p class="para">
     由于夏令时的缘故，这种方法比简单地在时间戳上加减一天或者一个月的秒数更可靠。
    </p>
   </p></blockquote>
  </p>
  <p class="para">
   一些使用 <span class="function"><strong>date()</strong></span>
   格式化日期的例子。注意要转义所有其它的字符，因为目前有特殊含义的字符会产生不需要的结果，而其余字符在
   PHP 将来的版本中可能会被用上。当转义时，注意用单引号以避免类似 \n 的字符变成了换行符。
   <div class="example" id="example-2238">
    <p><strong>Example #4 <span class="function"><strong>date()</strong></span> 格式举例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;假定今天是：March&nbsp;10th,&nbsp;2001,&nbsp;5:16:18&nbsp;pm<br /></span><span style="color: #0000BB">$today&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"F&nbsp;j,&nbsp;Y,&nbsp;g:i&nbsp;a"</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;March&nbsp;10,&nbsp;2001,&nbsp;5:16&nbsp;pm<br /></span><span style="color: #0000BB">$today&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"m.d.y"</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;03.10.01<br /></span><span style="color: #0000BB">$today&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"j,&nbsp;n,&nbsp;Y"</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;10,&nbsp;3,&nbsp;2001<br /></span><span style="color: #0000BB">$today&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"Ymd"</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;20010310<br /></span><span style="color: #0000BB">$today&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'h-i-s,&nbsp;j-m-y,&nbsp;it&nbsp;is&nbsp;w&nbsp;Day&nbsp;z&nbsp;'</span><span style="color: #007700">);&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;05-16-17,&nbsp;10-03-01,&nbsp;1631&nbsp;1618&nbsp;6&nbsp;Fripm01<br /></span><span style="color: #0000BB">$today&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'\i\t&nbsp;\i\s&nbsp;\t\h\e&nbsp;jS&nbsp;\d\a\y.'</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;It&nbsp;is&nbsp;the&nbsp;10th&nbsp;day.<br /></span><span style="color: #0000BB">$today&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"D&nbsp;M&nbsp;j&nbsp;G:i:s&nbsp;T&nbsp;Y"</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Sat&nbsp;Mar&nbsp;10&nbsp;15:16:08&nbsp;MST&nbsp;2001<br /></span><span style="color: #0000BB">$today&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'H:m:s&nbsp;\m&nbsp;\i\s\&nbsp;\m\o\n\t\h'</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;17:03:17&nbsp;m&nbsp;is&nbsp;month<br /></span><span style="color: #0000BB">$today&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"H:i:s"</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;17:16:17<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="para">
   要格式化其它语种的日期，应该用 <span class="function"><a href="function.setlocale.html" class="function">setlocale()</a></span> 和
   <span class="function"><a href="function.strftime.html" class="function">strftime()</a></span> 函数来代替 <span class="function"><strong>date()</strong></span>。
  </p>
  <p class="para">
   参见 <span class="function"><a href="function.getlastmod.html" class="function">getlastmod()</a></span>，<span class="function"><a href="function.gmdate.html" class="function">gmdate()</a></span>，<span class="function"><a href="function.mktime.html" class="function">mktime()</a></span>，<span class="function"><a href="function.strftime.html" class="function">strftime()</a></span>
   和 <span class="function"><a href="function.time.html" class="function">time()</a></span>。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.date-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">format</code></em></dt>

     <dd>

      <p class="para">
       The format of the outputted date <span class="type"><a href="language.types.string.html" class="type string">string</a></span>. See the formatting
       options below. There are also several
       <a href="class.datetime.html#datetime.constants.types" class="link">predefined date constants</a>
       that may be used instead, so for example <strong><code>DATE_RSS</code></strong>
       contains the format string <em>&#039;D, d M Y H:i:s&#039;</em>.
      </p>
      <p class="para">
       <table class="doctable table">
        <caption><strong>The following characters are recognized in the
        <em><code class="parameter">format</code></em> parameter string</strong></caption>
        
         <thead>
          <tr>
           <th><em><code class="parameter">format</code></em> character</th>
           <th>Description</th>
           <th>Example returned values</th>
          </tr>

         </thead>

         <tbody class="tbody">
          <tr>
           <td style="text-align: center;"><em class="emphasis">Day</em></td>
           <td>---</td>
           <td>---</td>
          </tr>

          <tr>
           <td><em>d</em></td>
           <td>Day of the month, 2 digits with leading zeros</td>
           <td><em>01</em> to <em>31</em></td>
          </tr>

          <tr>
           <td><em>D</em></td>
           <td>A textual representation of a day, three letters</td>
           <td><em>Mon</em> through <em>Sun</em></td>
          </tr>

          <tr>
           <td><em>j</em></td>
           <td>Day of the month without leading zeros</td>
           <td><em>1</em> to <em>31</em></td>
          </tr>

          <tr>
           <td><em>l</em> (lowercase &#039;L&#039;)</td>
           <td>A full textual representation of the day of the week</td>
           <td><em>Sunday</em> through <em>Saturday</em></td>
          </tr>

          <tr>
           <td><em>N</em></td>
           <td>ISO-8601 numeric representation of the day of the week (added in
           PHP 5.1.0)</td>
           <td><em>1</em> (for Monday) through <em>7</em> (for Sunday)</td>
          </tr>

          <tr>
           <td><em>S</em></td>
           <td>English ordinal suffix for the day of the month, 2 characters</td>
           <td>
            <em>st</em>, <em>nd</em>, <em>rd</em> or
            <em>th</em>.  Works well with <em>j</em>
           </td>
          </tr>

          <tr>
           <td><em>w</em></td>
           <td>Numeric representation of the day of the week</td>
           <td><em>0</em> (for Sunday) through <em>6</em> (for Saturday)</td>
          </tr>

          <tr>
           <td><em>z</em></td>
           <td>The day of the year (starting from 0)</td>
           <td><em>0</em> through <em>365</em></td>
          </tr>

          <tr>
           <td style="text-align: center;"><em class="emphasis">Week</em></td>
           <td>---</td>
           <td>---</td>
          </tr>

          <tr>
           <td><em>W</em></td>
           <td>ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0)</td>
           <td>Example: <em>42</em> (the 42nd week in the year)</td>
          </tr>

          <tr>
           <td style="text-align: center;"><em class="emphasis">Month</em></td>
           <td>---</td>
           <td>---</td>
          </tr>

          <tr>
           <td><em>F</em></td>
           <td>A full textual representation of a month, such as January or March</td>
           <td><em>January</em> through <em>December</em></td>
          </tr>

          <tr>
           <td><em>m</em></td>
           <td>Numeric representation of a month, with leading zeros</td>
           <td><em>01</em> through <em>12</em></td>
          </tr>

          <tr>
           <td><em>M</em></td>
           <td>A short textual representation of a month, three letters</td>
           <td><em>Jan</em> through <em>Dec</em></td>
          </tr>

          <tr>
           <td><em>n</em></td>
           <td>Numeric representation of a month, without leading zeros</td>
           <td><em>1</em> through <em>12</em></td>
          </tr>

          <tr>
           <td><em>t</em></td>
           <td>Number of days in the given month</td>
           <td><em>28</em> through <em>31</em></td>
          </tr>

          <tr>
           <td style="text-align: center;"><em class="emphasis">Year</em></td>
           <td>---</td>
           <td>---</td>
          </tr>

          <tr>
           <td><em>L</em></td>
           <td>Whether it&#039;s a leap year</td>
           <td><em>1</em> if it is a leap year, <em>0</em> otherwise.</td>
          </tr>

          <tr>
           <td><em>o</em></td>
           <td>ISO-8601 year number. This has the same value as
            <em>Y</em>, except that if the ISO week number
            (<em>W</em>) belongs to the previous or next year, that year
            is used instead. (added in PHP 5.1.0)</td>
           <td>Examples: <em>1999</em> or <em>2003</em></td>
          </tr>

          <tr>
           <td><em>Y</em></td>
           <td>A full numeric representation of a year, 4 digits</td>
           <td>Examples: <em>1999</em> or <em>2003</em></td>
          </tr>

          <tr>
           <td><em>y</em></td>
           <td>A two digit representation of a year</td>
           <td>Examples: <em>99</em> or <em>03</em></td>
          </tr>

          <tr>
           <td style="text-align: center;"><em class="emphasis">Time</em></td>
           <td>---</td>
           <td>---</td>
          </tr>

          <tr>
           <td><em>a</em></td>
           <td>Lowercase Ante meridiem and Post meridiem</td>
           <td><em>am</em> or <em>pm</em></td>
          </tr>

          <tr>
           <td><em>A</em></td>
           <td>Uppercase Ante meridiem and Post meridiem</td>
           <td><em>AM</em> or <em>PM</em></td>
          </tr>

          <tr>
           <td><em>B</em></td>
           <td>Swatch Internet time</td>
           <td><em>000</em> through <em>999</em></td>
          </tr>

          <tr>
           <td><em>g</em></td>
           <td>12-hour format of an hour without leading zeros</td>
           <td><em>1</em> through <em>12</em></td>
          </tr>

          <tr>
           <td><em>G</em></td>
           <td>24-hour format of an hour without leading zeros</td>
           <td><em>0</em> through <em>23</em></td>
          </tr>

          <tr>
           <td><em>h</em></td>
           <td>12-hour format of an hour with leading zeros</td>
           <td><em>01</em> through <em>12</em></td>
          </tr>

          <tr>
           <td><em>H</em></td>
           <td>24-hour format of an hour with leading zeros</td>
           <td><em>00</em> through <em>23</em></td>
          </tr>

          <tr>
           <td><em>i</em></td>
           <td>Minutes with leading zeros</td>
           <td><em>00</em> to <em>59</em></td>
          </tr>

          <tr>
           <td><em>s</em></td>
           <td>Seconds, with leading zeros</td>
           <td><em>00</em> through <em>59</em></td>
          </tr>

          <tr>
           <td><em>u</em></td>
           <td>Microseconds (added in PHP 5.2.2)</td>
           <td>Example: <em>654321</em></td>
          </tr>

          <tr>
           <td style="text-align: center;"><em class="emphasis">Timezone</em></td>
           <td>---</td>
           <td>---</td>
          </tr>

          <tr>
           <td><em>e</em></td>
           <td>Timezone identifier (added in PHP 5.1.0)</td>
           <td>Examples: <em>UTC</em>, <em>GMT</em>, <em>Atlantic/Azores</em></td>
          </tr>

          <tr>
           <td><em>I</em> (capital i)</td>
           <td>Whether or not the date is in daylight saving time</td>
           <td><em>1</em> if Daylight Saving Time, <em>0</em> otherwise.</td>
          </tr>

          <tr>
           <td><em>O</em></td>
           <td>Difference to Greenwich time (GMT) in hours</td>
           <td>Example: <em>+0200</em></td>
          </tr>

          <tr>
           <td><em>P</em></td>
           <td>Difference to Greenwich time (GMT) with colon between hours and minutes (added in PHP 5.1.3)</td>
           <td>Example: <em>+02:00</em></td>
          </tr>

          <tr>
           <td><em>T</em></td>
           <td>Timezone abbreviation</td>
           <td>Examples: <em>EST</em>, <em>MDT</em> ...</td>
          </tr>

          <tr>
           <td><em>Z</em></td>
           <td>Timezone offset in seconds. The offset for timezones west of UTC is always
           negative, and for those east of UTC is always positive.</td>
           <td><em>-43200</em> through <em>50400</em></td>
          </tr>

          <tr>
           <td style="text-align: center;"><em class="emphasis">Full Date/Time</em></td>
           <td>---</td>
           <td>---</td>
          </tr>

          <tr>
           <td><em>c</em></td>
           <td>ISO 8601 date (added in PHP 5)</td>
           <td>2004-02-12T15:19:21+00:00</td>
          </tr>

          <tr>
           <td><em>r</em></td>
           <td><a href="http://www.faqs.org/rfcs/rfc2822" class="link external">&raquo;&nbsp;RFC 2822</a> formatted date</td>
           <td>Example: <em>Thu, 21 Dec 2000 16:01:07 +0200</em></td>
          </tr>

          <tr>
           <td><em>U</em></td>
           <td>Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)</td>
           <td>See also <span class="function"><a href="function.time.html" class="function">time()</a></span></td>
          </tr>

         </tbody>
        
       </table>

      </p>
      <p class="para">
       Unrecognized characters in the format string will be printed
       as-is.  The <em>Z</em> format will always return
       <em>0</em> when using <span class="function"><a href="function.gmdate.html" class="function">gmdate()</a></span>.
      </p>       
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <p class="para">
        Since this function only accepts <span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span> timestamps the
        <em>u</em> format character is only useful when using the
        <span class="function"><a href="function.date-format.html" class="function">date_format()</a></span> function with user based timestamps
        created with <span class="function"><a href="function.date-create.html" class="function">date_create()</a></span>.
       </p>
      </p></blockquote>
     </dd>

    
    
    <dt>
<em><code class="parameter">timestamp</code></em></dt>
<dd>
<p class="para">
可选的 <em><code class="parameter">timestamp</code></em> 参数是一个 <span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span> 的 Unix
时间戳，如未指定，参数值默认为当前本地时间。也就是说，其值默认为
<span class="function"><a href="function.time.html" class="function">time()</a></span> 的返回值。</p></dd>

   
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.date-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns a formatted date string. If a non-numeric value is used for 
   <em><code class="parameter">timestamp</code></em>, <strong><code>FALSE</code></strong> is returned and an 
   <strong><code>E_WARNING</code></strong> level error is emitted.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.date-errors">
  <h3 class="title">错误／异常</h3>
   
   <p class="para">
在每 次调用日期/时间函数时，如果时区无效则会引发 <strong><code>E_NOTICE</code></strong> 错误，如果使用系统设定值或 <var class="varname"><var class="varname">TZ</var></var>
环境变量，则会引发 <strong><code>E_STRICT</code></strong> 或 <strong><code>E_WARNING</code></strong> 消息。参见
<span class="function"><a href="function.date-default-timezone-set.html" class="function">date_default_timezone_set()</a></span>。</p>
 
 </div>


 <div class="refsect1 changelog" id="refsect1-function.date-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>5.1.0</td>
       <td>
        The valid range of a timestamp is typically from Fri, 13 Dec
        1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are
        the dates that correspond to the minimum and maximum values for
        a 32-bit signed integer). However, before PHP 5.1.0 this range was limited
        from 01-01-1970 to 19-01-2038 on some systems (e.g. Windows).
       </td>
      </tr>

      
      <tr><td>5.1.0</td><td><p class="para">
现在发布 <strong><code>E_STRICT</code></strong> 和 <strong><code>E_NOTICE</code></strong>
时区错误。</p></td></tr>


      <tr>
       <td>5.1.1</td>
       <td>
        There are useful <a href="datetime.constants.html" class="link">constants</a> 
        of standard date/time formats that can be used to specify the 
        <em><code class="parameter">format</code></em> parameter.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.date-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2239">
    <p><strong>Example #5 <span class="function"><strong>date()</strong></span> examples</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;set&nbsp;the&nbsp;default&nbsp;timezone&nbsp;to&nbsp;use.&nbsp;Available&nbsp;since&nbsp;PHP&nbsp;5.1<br /></span><span style="color: #0000BB">date_default_timezone_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'UTC'</span><span style="color: #007700">);<br /><br /><br /></span><span style="color: #FF8000">//&nbsp;Prints&nbsp;something&nbsp;like:&nbsp;Monday<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"l"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Prints&nbsp;something&nbsp;like:&nbsp;Monday&nbsp;8th&nbsp;of&nbsp;August&nbsp;2005&nbsp;03:12:46&nbsp;PM<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'l&nbsp;jS&nbsp;\of&nbsp;F&nbsp;Y&nbsp;h:i:s&nbsp;A'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Prints:&nbsp;July&nbsp;1,&nbsp;2000&nbsp;is&nbsp;on&nbsp;a&nbsp;Saturday<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"July&nbsp;1,&nbsp;2000&nbsp;is&nbsp;on&nbsp;a&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"l"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mktime</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">7</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2000</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">/*&nbsp;use&nbsp;the&nbsp;constants&nbsp;in&nbsp;the&nbsp;format&nbsp;parameter&nbsp;*/<br />//&nbsp;prints&nbsp;something&nbsp;like:&nbsp;Mon,&nbsp;15&nbsp;Aug&nbsp;2005&nbsp;15:12:46&nbsp;UTC<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #0000BB">DATE_RFC822</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;prints&nbsp;something&nbsp;like:&nbsp;2000-07-01T00:00:00+00:00<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #0000BB">DATE_ATOM</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mktime</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">7</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2000</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="para">
   You can prevent a recognized character in the format string from being
   expanded by escaping it with a preceding backslash. If the character with
   a backslash is already a special sequence, you may need to also escape
   the backslash.
   <div class="example" id="example-2240">
    <p><strong>Example #6 Escaping characters in <span class="function"><strong>date()</strong></span></strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;prints&nbsp;something&nbsp;like:&nbsp;Wednesday&nbsp;the&nbsp;15th<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'l&nbsp;\t\h\e&nbsp;jS'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="para">
   It is possible to use <span class="function"><strong>date()</strong></span> and
   <span class="function"><a href="function.mktime.html" class="function">mktime()</a></span> together to find dates in the future
   or the past.
   <div class="example" id="example-2241">
    <p><strong>Example #7 <span class="function"><strong>date()</strong></span> and <span class="function"><a href="function.mktime.html" class="function">mktime()</a></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$tomorrow&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mktime</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"m"</span><span style="color: #007700">)&nbsp;&nbsp;,&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"d"</span><span style="color: #007700">)+</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"Y"</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$lastmonth&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mktime</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"m"</span><span style="color: #007700">)-</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"d"</span><span style="color: #007700">),&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"Y"</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$nextyear&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mktime</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"m"</span><span style="color: #007700">),&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"d"</span><span style="color: #007700">),&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"Y"</span><span style="color: #007700">)+</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
   <blockquote class="note"><p><strong class="note">Note</strong>: 
    <p class="para">
     This can be more reliable than simply adding or subtracting the number
     of seconds in a day or month to a timestamp because of daylight saving
     time.
    </p>
   </p></blockquote>
  </p>
  <p class="para">
   Some examples of <span class="function"><strong>date()</strong></span> formatting. Note that
   you should escape any other characters, as any which currently
   have a special meaning will produce undesirable results, and
   other characters may be assigned meaning in future PHP versions.
   When escaping, be sure to use single quotes to prevent characters
   like \n from becoming newlines.
   <div class="example" id="example-2242">
    <p><strong>Example #8 <span class="function"><strong>date()</strong></span> Formatting</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Assuming&nbsp;today&nbsp;is&nbsp;March&nbsp;10th,&nbsp;2001,&nbsp;5:16:18&nbsp;pm,&nbsp;and&nbsp;that&nbsp;we&nbsp;are&nbsp;in&nbsp;the<br />//&nbsp;Mountain&nbsp;Standard&nbsp;Time&nbsp;(MST)&nbsp;Time&nbsp;Zone<br /><br /></span><span style="color: #0000BB">$today&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"F&nbsp;j,&nbsp;Y,&nbsp;g:i&nbsp;a"</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;March&nbsp;10,&nbsp;2001,&nbsp;5:16&nbsp;pm<br /></span><span style="color: #0000BB">$today&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"m.d.y"</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;03.10.01<br /></span><span style="color: #0000BB">$today&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"j,&nbsp;n,&nbsp;Y"</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;10,&nbsp;3,&nbsp;2001<br /></span><span style="color: #0000BB">$today&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"Ymd"</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;20010310<br /></span><span style="color: #0000BB">$today&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'h-i-s,&nbsp;j-m-y,&nbsp;it&nbsp;is&nbsp;w&nbsp;Day'</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;05-16-18,&nbsp;10-03-01,&nbsp;1631&nbsp;1618&nbsp;6&nbsp;Satpm01<br /></span><span style="color: #0000BB">$today&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'\i\t&nbsp;\i\s&nbsp;\t\h\e&nbsp;jS&nbsp;\d\a\y.'</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;it&nbsp;is&nbsp;the&nbsp;10th&nbsp;day.<br /></span><span style="color: #0000BB">$today&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"D&nbsp;M&nbsp;j&nbsp;G:i:s&nbsp;T&nbsp;Y"</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Sat&nbsp;Mar&nbsp;10&nbsp;17:16:18&nbsp;MST&nbsp;2001<br /></span><span style="color: #0000BB">$today&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'H:m:s&nbsp;\m&nbsp;\i\s\&nbsp;\m\o\n\t\h'</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;17:03:18&nbsp;m&nbsp;is&nbsp;month<br /></span><span style="color: #0000BB">$today&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"H:i:s"</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;17:16:18<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="para">
   To format dates in other languages, you should use the
   <span class="function"><a href="function.setlocale.html" class="function">setlocale()</a></span> and <span class="function"><a href="function.strftime.html" class="function">strftime()</a></span>
   functions instead of <span class="function"><strong>date()</strong></span>.
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.date-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    To generate a timestamp from a string representation of the date, you
    may be able to use <span class="function"><a href="function.strtotime.html" class="function">strtotime()</a></span>. Additionally, some
    databases have functions to convert their date formats into timestamps
    (such as MySQL&#039;s <a href="http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html" class="link external">&raquo;&nbsp;UNIX_TIMESTAMP</a>
    function).
   </p>
  </p></blockquote>
  <div class="tip"><strong class="tip">Tip</strong>
   <p class="para">
    Timestamp of the start of the request is available in
    <var class="varname"><var class="varname"><a href="reserved.variables.server.html" class="classname">$_SERVER['REQUEST_TIME']</a></var></var> since PHP 5.1.
   </p>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.date-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.gmdate.html" class="function" rel="rdfs-seeAlso">gmdate()</a> - 格式化一个 GMT/UTC 日期／时间</span></li>
    <li class="member"><span class="function"><a href="function.idate.html" class="function" rel="rdfs-seeAlso">idate()</a> - 将本地时间日期格式化为整数</span></li>
    <li class="member"><span class="function"><a href="function.getdate.html" class="function" rel="rdfs-seeAlso">getdate()</a> - 取得日期／时间信息</span></li>
    <li class="member"><span class="function"><a href="function.getlastmod.html" class="function" rel="rdfs-seeAlso">getlastmod()</a> - 获取页面最后修改的时间</span></li>
    <li class="member"><span class="function"><a href="function.mktime.html" class="function" rel="rdfs-seeAlso">mktime()</a> - 取得一个日期的 Unix 时间戳</span></li>
    <li class="member"><span class="function"><a href="function.strftime.html" class="function" rel="rdfs-seeAlso">strftime()</a> - 根据区域设置格式化本地时间／日期</span></li>
    <li class="member"><span class="function"><a href="function.time.html" class="function" rel="rdfs-seeAlso">time()</a> - 返回当前的 Unix 时间戳</span></li>
    <li class="member"><span class="function"><a href="function.strtotime.html" class="function" rel="rdfs-seeAlso">strtotime()</a> - 将任何英文文本的日期时间描述解析为 Unix 时间戳</span></li>
    <li class="member"><a href="class.datetime.html#datetime.constants.types" class="link">Predefined DateTime Constants</a></li>
   </ul>
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.date-timezone-set.html">date_timezone_set</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.getdate.html">getdate</a></div>
 <div class="up"><a href="ref.datetime.html">Date/Time 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
